package cn.imvc.app.repositories;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import cn.imvc.app.entities.Goods;
import cn.imvc.data.jpa.repository.ISqlExecutor;

/**
 * 商品
 * 
 * @author lijibo
 *
 */
public interface GoodsRepository extends JpaRepository<Goods, Integer>,ISqlExecutor<Object> {
	/**
	 * 根据品牌获取商品分页列表
	 * @param brandId
	 * @param pageable
	 * @return
	 */
	Page<Goods> findByBrandIdAndState(int brandId, Byte state,Pageable pageable);
	/**
	 * 根据分类获取商品分页列表
	 * @param goodsClassId
	 * @param pageable
	 * @return
	 */
	Page<Goods> findByGoodsClassIdAndState(Integer goodsClassId,Byte state, Pageable pageable);
	/**
	 * 查询热销商品
	 * @param limitNum
	 * @return
	 */
	@Query(value = "select g.* from Goods g  where g.state = ?1 order by g.salenum  desc limit ?2", nativeQuery = true)
	List<Goods> findTopListOrderBySaleNum(byte state,Integer limitNum);
	/**
	 * 根据id集合获取列表
	 * @param goodsIds
	 * @return
	 */
	List<Goods> findByIdIn(int[] goodsIds);
}
